<template>
    <view class="victory-container">
        <!-- 胜利图标和装饰 -->
        <view class="victory-icon">
            <image v-if="isVictory" src="/static/shengliqingzhu.png" mode="heightFix" style="width: 100%;height: 100%;">
            </image>
            <image v-else src="/static/weishengli.png" mode="heightFix" style="width: 100%;height: 100%;"></image>
        </view>

        <!-- 胜利文字 -->
        <view class="victory-text">
            <view class="congratulation" v-if="isVictory">恭喜你获得本场</view>
            <view class="congratulation" v-else>很遗再接再厉！你获得本场</view>
            <view class="rank-number">第 {{ mingci }} 名</view>
            <view class="points-earned" v-if="isVictory">
                <text class="points-number">+{{ points }}</text>
                <text class="points-label">积分</text>
            </view>
        </view>

        <!-- 操作按钮 -->
        <view class="action-buttons">
            <view class="action-btn view-ranking" @click="handleViewRanking">
                查看排名
            </view>
            <view class="action-btn play-again" @click="handlePlayAgain">
                再来一场
            </view>
        </view>
    </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// 定义组件属性
const props = defineProps({
    points: {
        type: Number,
        default: 80
    },
    isVictory: {
        type: Boolean,
        default: true
    },
    mingci: {
        type: Number,
        default: 1
    },
    room_id: {
        type: String,
        default: ''
    }
})

// 定义组件事件
const emit = defineEmits(['view-ranking', 'play-again'])

// 处理查看排名
const handleViewRanking = () => {
   uni.navigateTo({
        url: '/pages/index/datiqian/ranking/ranking?room_id=' + props.room_id
    })
}

// 处理再来一场
const handlePlayAgain = () => {
    uni.switchTab({
        url: '/pages/index/index'
    })
}

// 获取彩纸样式
const getConfettiStyle = (index) => {
    const colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7', '#DDA0DD', '#98D8C8', '#F7DC6F']
    const color = colors[index % colors.length]
    const left = Math.random() * 100
    const animationDelay = Math.random() * 2
    const animationDuration = 2 + Math.random() * 2
    
    return {
        left: `${left}%`,
        backgroundColor: color,
        animationDelay: `${animationDelay}s`,
        animationDuration: `${animationDuration}s`
    }
}

// 组件挂载时的动画效果
onMounted(() => {
    // 可以在这里添加一些初始化动画
})
</script>

<style lang="scss" scoped>
.victory-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.victory-icon {
    position: relative;
    margin-bottom: 80rpx;
    margin-top: 100rpx;
    height: 300rpx;
}

.planet-icon {
    position: relative;
    width: 120rpx;
    height: 120rpx;
}

.planet-core {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #4A90E2, #357ABD);
    border-radius: 50%;
    position: relative;
    box-shadow: 0 8rpx 24rpx rgba(74, 144, 226, 0.3);
}

.planet-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 160rpx;
    height: 40rpx;
    border: 6rpx solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

.confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.confetti {
    position: absolute;
    width: 12rpx;
    height: 12rpx;
    border-radius: 2rpx;
    animation: confettiFall linear infinite;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-100rpx) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(400rpx) rotate(360deg);
        opacity: 0;
    }
}

.victory-text {
    text-align: center;
    margin-bottom: 120rpx;
}

.congratulation {
    font-size: 28rpx;
    color: rgba(0, 0, 0, 0.6);
    margin-bottom: 32rpx;
}

.rank-number {
    font-size: 72rpx;
    font-weight: 700;
    color: rgba(0, 0, 0, 0.9);
    margin-bottom: 80rpx;
}

.points-earned {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8rpx;
}

.points-number {
    font-size: 40rpx;
    font-weight: 600;
    color: #0F50DC;
}

.points-label {
    font-size: 24rpx;
    color: rgba(15, 80, 220, 0.7);
}

.action-buttons {
    display: flex;
    gap: 24rpx;
    width: 100%;
}

.action-btn {
    width: 280rpx;
    height: 80rpx;
    line-height: 80rpx;
    text-align: center;
    border-radius: 64rpx;
    font-size: 32rpx;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.view-ranking {
    background: #fff;
    color: #666;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.view-ranking:hover {
    background: #f5f5f5;
    border-color: #ccc;
}

.play-again {
    background: #0F50DC;
    color: #fff;
}

.play-again:hover {
    background: #0F50DC;
    color: #fff;
}

/* 响应式设计 */
@media (max-width: 750rpx) {
    .victory-container {
        padding: 20rpx;
    }
    
    .rank-number {
        font-size: 60rpx;
    }
    
    .action-buttons {
        flex-direction: column;
        gap: 16rpx;
    }
    
    .action-btn {
        width: 100%;
    }
}
</style>
